<template>
    <div class="bg">
        <img src="/src/status/bgTu.png" class="bgImg" alt="">
        <div class="login">
            <div class="logo f f-a-c f-j-c">
                <img src="/src/status/logo.png" class="logoImg" alt="">
            </div>
            <!-- 这个是title -->
            <div class="problem">H.S.国际问题研究平台</div>
            <!-- 上面的inpt -->
            <div class="inp1">
                <div class="inpHao">账号邮箱/编号</div>
                <input type="text" v-model="inp1Value" placeholder="输入账号邮箱/编号" class="inp" name="" id="">
            </div>
            <div class="inp1">
                <div class="inpHao">登录密码</div>
                <input type="password" v-model="inp2Value" placeholder="输入登录密码" class="inp" name="" id="">
            </div>
            <!-- /按钮 -->
            <div @click="login" class="loginBtn">登录</div>
        </div>
    </div>
</template> 

<script setup>
import { ref } from 'vue'
import { userLogin } from '../../api/index'
import { ElMessage } from 'element-plus'
import { setToken } from '../../utils/auth'
import router from '../../router';
let inp1Value = ref('')
let inp2Value = ref('')
// 点击登录
const login = async () => {
    if (!inp1Value.value || !inp2Value.value) {
        showToast('请输入完整账号密码');
    }
    let n = await userLogin({ account: inp1Value.value, password: inp2Value.value })
    console.log(n, '0.0.0.00.0');
    if (n.code != 200) {
        ElMessage({
            message: n.msg,
            type: 'error',
        })
    } else {
        ElMessage({
            message: n.msg,
            type: 'success',
        })
        // 当登录成功的时候
        setToken(n.content.token)
        localStorage.setItem('userinfo', JSON.stringify(n.content))
        router.push('/')
    }

}
</script>
<style  scoped>
@import './index.scss'
</style>